package com.fowo.api.service.handleWork;

import com.fowo.api.model.loan.now.balance.LoanNowBalanceFinishRequestPayoutAction;
import com.fowo.api.model.loan.now.balance.LoanNowBalanceVo;
import com.fowo.api.service.LoanNowBalanceService;
import com.fowo.api.service.PurchaseOrderService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

import javax.annotation.Resource;

@Component
public class LoanNowBalanceFinishRequestPayout implements LoanNowBalanceFinishRequestPayoutAction {

    @Resource
    private LoanNowBalanceService loanNowBalanceService;
    @Resource
    private PurchaseOrderService purchaseOrderService;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void run(Long id) throws Exception {
        LoanNowBalanceVo voById = loanNowBalanceService.getVoById(id);
        Assert.notNull(voById,"改单据不存在");
        voById.setStatus("40");
        loanNowBalanceService.update(voById);
//        for(LoanNowBalanceProductItemVo itemVo : voById.getOrderLists()){
//            PurchaseOrderVo purchaseOrderVo = purchaseOrderService.getVoById(itemVo.getPurchaseOrderCode());
//            //TODO 更新采购订单 支付状态为 已付清
//        }
    }
}
